package com.qfedu.controller;

import com.alibaba.fastjson.JSONObject;
import com.qfedu.entity.Comment;
import com.qfedu.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zhang
 * @Title: commonValidateAdd
 * @date : 2022/2/23 19:37
 */
@Controller
public class CommentController {
    @Autowired
    private CommentService commentService;

    @RequestMapping("/comment/songList/detail")
    @ResponseBody
    public List<Comment> findAllComment(int songListId){
        System.out.println(commentService.findAllComment(songListId));
        return commentService.findAllComment(songListId);
    }

    @RequestMapping("/comment/update")
    @ResponseBody
    public JSONObject updateComment(Comment comment){
        int i = commentService.updateComment(comment);

        System.out.println(comment);
        JSONObject jsonObject = new JSONObject();
        if (i > 0){
            jsonObject.put("code",1);
            jsonObject.put("msg","修改成功");
        }else {
            jsonObject.put("code",0);
            jsonObject.put("msg","修改失败");
        }
        return jsonObject;

    }

    @RequestMapping("/comment/delete")
    @ResponseBody
    public int deleteComment(Comment comment) {
        return commentService.deleteComment(comment);
    }

    @RequestMapping("/comment/song/detail")
    @ResponseBody
    public List<Comment> findComment(int songId) {
        return commentService.findComment(songId);
    }


}
